package com.yx.ehis.system;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.ICoolBarManager;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineLayoutData;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;

import com.yx.system.model.Context;
import com.yx.system.util.SystemTools;

public class ApplicationActionBarAdvisor extends ActionBarAdvisor {
	private IWorkbenchAction exitAction;
	private IWorkbenchAction aboutAction;
	private Action restartAction;

	public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
		super(configurer);
	}

	@Override
	protected void makeActions(IWorkbenchWindow window) {
		aboutAction = ActionFactory.ABOUT.create(window);
		aboutAction.setText("关于(&A)");
		aboutAction.setImageDescriptor(PlatformUI.getWorkbench()
				.getSharedImages()
				.getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
		register(aboutAction);

		exitAction = ActionFactory.QUIT.create(window);
		exitAction.setText("退出(&Q)");
		exitAction.setImageDescriptor(PlatformUI.getWorkbench()
				.getSharedImages()
				.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
		register(exitAction);

		restartAction = new Action("重启(&R)") {
			@Override
			public void run() {
				PlatformUI.getWorkbench().restart();
			}
		};
		restartAction.setToolTipText("重启应用程序");
		restartAction.setImageDescriptor(Activator
				.getImageDescriptor("/icons/window.png"));
	}

	// 菜单条
	@Override
	protected void fillMenuBar(IMenuManager menuBar) {
		MenuManager fileManager = new MenuManager("文件(&F)",
				IWorkbenchActionConstants.M_FILE);
		fileManager.add(aboutAction);
		MenuManager optionManager = new MenuManager("操作(&P)", "option");// 定义二级菜单
		optionManager.add(restartAction);
		optionManager.add(exitAction);
		fileManager.add(optionManager);
		menuBar.add(fileManager);
	}

	// 工具条
	@Override
	protected void fillCoolBar(ICoolBarManager coolBar) {
		IToolBarManager toolbar1 = new ToolBarManager(coolBar.getStyle());
		toolbar1.add(restartAction);
		coolBar.add(toolbar1);
	}

	// 状态线
	@Override
	protected void fillStatusLine(IStatusLineManager statusLine) {
		statusLine.add(new ContributionItem() {
			@Override
			public void fill(Composite parent) {
				StatusLineLayoutData statusLineLayoutData;

				Label separator_0 = new Label(parent, SWT.SEPARATOR);
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.heightHint = 20;
				separator_0.setLayoutData(statusLineLayoutData);

				CLabel label_0 = new CLabel(parent, SWT.SHADOW_NONE);
				label_0.setImage(SystemTools.getImage("icons/copyright.png"));
				label_0.setToolTipText("CopyRight 2015 By YXKJ Co., Ltd. All Rights Reserved.");
				label_0.setText("CopyRight 2015 By YXKJ Co., Ltd. All Rights Reserved.");
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.widthHint = 350;
				label_0.setLayoutData(statusLineLayoutData);

				Label separator_1 = new Label(parent, SWT.SEPARATOR);
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.heightHint = 20;
				separator_1.setLayoutData(statusLineLayoutData);

				CLabel label_1 = new CLabel(parent, SWT.SHADOW_NONE);
				label_1.setImage(SystemTools.getImage("icons/server.png"));
				label_1.setToolTipText("数据库服务器:255.255.255.255");
				label_1.setText("255.255.255.255");
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.widthHint = 120;
				label_1.setLayoutData(statusLineLayoutData);

				Label separator_2 = new Label(parent, SWT.SEPARATOR);
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.heightHint = 20;
				separator_2.setLayoutData(statusLineLayoutData);

				CLabel label_2 = new CLabel(parent, SWT.SHADOW_NONE);
				label_2.setImage(SystemTools.getImage("icons/workstation.png"));
				label_2.setToolTipText("当前工作站:医生工作站");
				label_2.setText("医生工作站");
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.widthHint = 90;
				label_2.setLayoutData(statusLineLayoutData);

				Label separator_3 = new Label(parent, SWT.SEPARATOR);
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.heightHint = 20;
				separator_3.setLayoutData(statusLineLayoutData);

				CLabel label_3 = new CLabel(parent, SWT.SHADOW_NONE);
				label_3.setImage(SystemTools.getImage("icons/version.png"));
				label_3.setToolTipText("当前程序版本:"
						+ Context.getInstance().getVersion());
				label_3.setText(Context.getInstance().getVersion());
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.widthHint = 80;
				label_3.setLayoutData(statusLineLayoutData);

				Label separator_4 = new Label(parent, SWT.SEPARATOR);
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.heightHint = 20;
				separator_4.setLayoutData(statusLineLayoutData);

				CLabel label_4 = new CLabel(parent, SWT.SHADOW_NONE);
				label_4.setImage(SystemTools.getImage("icons/user.png"));
				label_4.setToolTipText("当前用户:张三丰丰");
				label_4.setText("张三丰丰");
				statusLineLayoutData = new StatusLineLayoutData();
				statusLineLayoutData.widthHint = 80;
				label_4.setLayoutData(statusLineLayoutData);
			}
		});
	}
}
